<template>
	<view>
		<free-nav-bar title="通知公告" showBack></free-nav-bar>

		<view class="pl-3 pr-3 lineHight-3 border-f5f5f5" v-for="(notice, index) in notices" :key="index"
			@click="getDiClick(notice.id)">
			<text v-if="!notice.isRead" @click="readNotice(index)" style="color: #FF0000; padding-right: 5px;">●</text>
			<text @click="readNotice(index)"
				:style="{ color: notice.isRead ? '#999999' :  '#333'}">{{ notice.title }}</text>
		</view>
	</view>
</template>

<script>
	import $H from '@/common/free-lib/request.js';
	import freeNavBar from "@/components/free-ui/free-nav-bar.vue"
	export default {
		components: {
			freeNavBar
		},
		data() {
			return {
				notices: [],
				pageNo: 1,
				pageSize: 10
			}
		},
		onLoad() {
			this.getNoticeList(this.pageNo, this.pageSize);
		},
		onReachBottom() {
			this.pageNo = this.pageNo + 1;
			this.getNoticeList(this.pageNo, this.pageSize);
		},
		methods: {
			readNotice(index) {
				this.notices[index].isRead = true; // 点击浏览后将未读状态设置为已读
			},
			getDiClick(id) {
				uni.navigateTo({
					url: '/pages/tabbar/index/NewListDi?id='+id
				})
			},
			getNoticeList(no, size) {
				$H.get('/basisInform/platformNotice/upper/list', {
						pageNo: no,
						pageSize: size
					}, {})
					.then(res => {
						if(res.result.records.length==0){
							uni.showToast({
								title: '没有更多啦！',
								icon: 'success'
							});
							return;
						}
						const noticeList = [];
						for (let i = 0; i < res.result.records.length; i++) {
							if (res.result.records[i].title) {
								noticeList.push({
									id:res.result.records[i].id,
									title: res.result.records[i].title,
									isRead: res.result.records[i].isRead
								});
							}
						}
						this.notices = noticeList;
					})
					.catch(error => {
						console.error('请求出错', error); // 处理任何错误  
					});
			}
		}
	}
</script>
<style>
</style>